import pymysql

print("用户注册")

user = input("请输入用户名：")
password = input("请输入密码：")

# 连接指定数据
conn = pymysql.connect(host="139.159.152.73", port=3306, user='root', passwd='Python666..', charset='utf8')
cursor = conn.cursor()

# 执行SQL语句
sqll = "CREATE USER %s@'139.159.152.73' IDENTIFIED BY %s;"
cursor.execute(sqll, (user, password))
conn.commit()

# 设置只设置可读取权限
sqlll = "grant select on *.* to %s@'139.159.152.73';"
cursor.execute(sqlll, user)
conn.commit()

# 关闭数据库连接
cursor.close()
conn.close()
print("注册用户成功，用户名：{}，密码：{}".format(user, password))